/**
 * Author: w景洋.
 * Time: 2016/4/19 0019
 */
angular.module('entrance.service.shop', [
    "ngResource"
])
    //获取商店列表
    .service('Entrance_ShopService',['$resource',function($resource){
        var shop_map = {};
        
        //获取县镇商店菜单
        this.selectAllCountyShops = function(countyid){
            var Shoplist =  $resource(mallurl+'/shoplist/:id', {}, {
                get: {cache: true, method: 'GET'},
                query: {cache: true, method: 'GET', isArray: true}
            });
            return Shoplist.query({id:countyid}, function(data){
                for (var i=0; i<data.length; i++) {
                    var town_shops = data[i];
                    for (var j=0; j<town_shops.shops.length; j++) {
                        var shop = town_shops.shops[j];
                        shop_map[shop.shopid] = shop;
                    }
                }
            });
        }

        //获取商店(优先从缓存读取)
        this.queryShopByShopid = function(shopid) {
            if (shop_map[shopid]) {
                return shop_map[shopid];
            }
            var shopres = $resource(mallurl+'/shops/:id', {}, {
                get: {cache: true, method: 'GET'}
            });
            return shopres.get({id:shopid});
        }

        //获取分组商店菜单
        this.queryShoplistByGroup = function(groupid) {
            var ShopByGroup =  $resource(mallurl+'/shops/bytag/:id', {}, {
                get: {cache: true, method: 'GET'},
                query: {cache: true, method: 'GET', isArray: true}
            });
            return ShopByGroup.query({id:groupid});
        }
        //获取店铺分类信息
        this.getAllShopByTag = function(){
            var allshop = $resource(mallurl+"shoplist/bytag");
            return allshop.query();
        }
        //根据区域获得商店
        this.queryShoplistByScope = function(scope) {
            console.log(scope)
            var ShopByScope =  $resource(mallurl+'/shopsscope/byscope/:area', {}, {
                get: {cache: true, method: 'GET'},
                query: {cache: true, method: 'GET', isArray: true}
            });
            return ShopByScope.query({area:scope});
        }

    }])
;
